<?php

namespace App\Models;

class Lives extends Base
{

    protected $table = 'lives';
    const STATUS_1 = 1;
    const STATUS_2 = 2;
    const STATUS_TEXT = [
        self::STATUS_1 => '<span class="el-tag">正常</span>',
        self::STATUS_2 => '<span class="el-tag el-tag--warning">锁定</span>',
    ];

    const POSITION_1 = 1;
    const POSITION_2 = 2;
    const POSITION_TEXT = [
        self::POSITION_1 => '<span class="el-tag">正常</span>',
        self::POSITION_2 => '<span class="el-tag el-tag--danger">推荐</span>',
    ];
    protected $fillable = [
        'id','content','source','status','position','created_at','updated_at','week'
    ];


    /**
     * 列表数据
     * @param int $limit
     * @return mixed
     */
    protected function list($limit = 20){
        $lists = $this->select(['content','source','created_at','week'])
            ->where('status',Lives::STATUS_1)
            ->orderBy('created_at', 'desc')
            ->paginate($limit)
            ->toArray();
        foreach ($lists['data'] as $key=>$item){
            $lists['data'][$item['week']]['week'] = $item['week'];
            $lists['data'][$item['week']]['created_at'] = $item['created_at'];
            $lists['data'][$item['week']]['child'][] = $item;
            unset($lists['data'][$key]);
        }
        $lists['data'] = array_values($lists['data']);
        return $lists;
    }

    /**
     * 查询快讯推荐
     * @return mixed
     */
    protected function positon(){
        return $this->select('id','content','source','created_at')
            ->where('position',Lives::POSITION_2)
            ->where('status',Lives::STATUS_1)
            ->orderBy('created_at', 'desc')
            ->take(10)
            ->get();
    }












}
